﻿using DocumentFormat.OpenXml.Lite.Core.ContentType;
using DocumentFormat.OpenXml.Lite.Core.Relationship;
using DocumentFormat.OpenXml.Lite.DrawingML.Style;
using DocumentFormat.OpenXml.Lite.WordprocessingML.Word.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DFS = DocumentFormat.OpenXml.Lite.Core.DocumentFS;

namespace DocumentFormat.OpenXml.Lite.WordprocessingML
{
    public static class Extensions
    {
        public static Theme CreateTheme(this Document doc)
        {
            Theme theme = new Theme();

            DFS.Directory sandbox = DFS.DocumentFS.GetSandbox(doc.Id);
            DFS.File themeFile = sandbox.GetDirectory("word/theme").CreateFile("theme" + theme.ToString() + ".xml", theme);

            var cManager = sandbox.GetFile("[Content_Types].xml").Object as ContentTypeManager;
            cManager.CreateOverride(ContentType.Theme, themeFile);

            var relManager = sandbox.GetFile("word/_rels/document.xml.rels").Object as RelationshipManager;
            relManager.CreateRelationship(RelationshipURI.Theme, themeFile, sandbox.GetDirectory("word"));

            return theme;
        }
    }
}
